﻿namespace Smart.Utils.UI.BarcodeLib
{
    using System;

    internal class Postnet : BarcodeCommon, IBarcode
    {
        private string[] POSTNET_Code = new string[] { "11000", "00011", "00101", "00110", "01001", "01010", "01100", "10001", "10010", "10100" };

        public Postnet(string input)
        {
            base.Raw_Data = input;
        }

        private string Encode_Postnet()
        {
            base.Raw_Data = base.Raw_Data.Replace("-", "");
            switch (base.Raw_Data.Length)
            {
                case 5:
                case 6:
                case 9:
                case 11:
                {
                    string str = "1";
                    int num = 0;
                    foreach (char ch in base.Raw_Data)
                    {
                        try
                        {
                            int num2 = Convert.ToInt32(ch.ToString());
                            str = str + this.POSTNET_Code[num2];
                            num += num2;
                        }
                        catch (Exception exception)
                        {
                            throw new Exception("EPOSTNET-2: Invalid data. (Numeric only) --> " + exception.Message);
                        }
                    }
                    int num3 = num % 10;
                    int index = 10 - ((num3 == 0) ? 10 : num3);
                    return (str + this.POSTNET_Code[index] + "1");
                }
            }
            throw new Exception("EPOSTNET-2: Invalid data length. (5, 6, 9, or 11 digits only)");
        }

        public string Encoded_Value
        {
            get
            {
                return this.Encode_Postnet();
            }
        }
    }
}

